package com.algorithm.base.backtracking;

import java.util.*;

/**
 * 子集
 * 收集叶子节点
 *
 * @author Amadeus
 * @date 2023/11/09
 */
public class Subsets {

    List<List<Integer>> result = new ArrayList<>();
    Deque<Integer> deque = new LinkedList<>();

    public List<List<Integer>> subsets(int[] nums) {
        backTracking(0, nums);

        return new ArrayList<>(result);
    }

    public void backTracking(int index, int[] nums) {
        result.add(new ArrayList<>(deque));

        for (int i = index; i < nums.length; i++) {
            deque.addLast(nums[i]);
            backTracking(i + 1, nums);
            deque.removeLast();
        }
    }

}
